﻿Imports System.Data
Imports TransportadoraToledoDAL
Public Class CombustiveisVeiculoBLL

    Dim objDAL As New CombustiveisVeiculosDAL

    Private vei_codigo As Integer
    Public Property pveicodigo() As Integer
        Get
            Return vei_codigo
        End Get
        Set(ByVal value As Integer)
            vei_codigo = value
        End Set
    End Property

    Private com_codigo As Integer
    Public Property pcomcodigo() As Integer
        Get
            Return com_codigo
        End Get
        Set(ByVal value As Integer)
            com_codigo = value
        End Set
    End Property

    Public Sub New()

    End Sub


    Public Sub New(ByVal vei_codigo As Integer, com_codigo As Integer)
        Try
            Dim tab As DataTable
            objDAL = New CombustiveisVeiculosDAL
            tab = objDAL.localizar(vei_codigo, com_codigo)
            If (tab.Rows.Count > 0) Then
                Me.vei_codigo = tab.Rows(0)("vei_codigo")
                Me.com_codigo = tab.Rows(0)("com_codigo")
            Else
                limpar()
            End If
        Catch ex As Exception
            Throw ex
        End Try
        objDAL = Nothing
    End Sub

    Public Sub limpar()
        Me.vei_codigo = Nothing
        Me.com_codigo = Nothing
    End Sub

    Public Sub incluir()
        Try
            If (Me.vei_codigo = 0 Or Me.com_codigo = 0) Then
                Throw New Exception("Preencha todos os campos")
            Else
                objDAL = New CombustiveisVeiculosDAL
                objDAL.incluir(vei_codigo, com_codigo)
            End If
        Catch ex As Exception
            Throw ex
        End Try
        objDAL = Nothing
    End Sub


    Public Sub excluirTodos(ByVal codigo As Integer)
        Try
            objDAL = New CombustiveisVeiculosDAL
            objDAL.excluirTodos(codigo)
        Catch ex As Exception
            Throw ex
        End Try
        objDAL = Nothing
    End Sub

    Public Function localizarTodos(ByVal codigo As Integer) As DataTable
        Dim tab As DataTable
        Try
            objDAL = New CombustiveisVeiculosDAL
            tab = objDAL.localizarTodos(codigo)
        Catch ex As Exception
            Throw ex
        End Try
        Return tab
    End Function

    Public Function localizar(ByVal codigo As Integer) As DataTable
        Dim tab As DataTable
        Try
            objDAL = New CombustiveisVeiculosDAL
            tab = objDAL.localizar(codigo)
        Catch ex As Exception
            Throw ex
        End Try
        Return tab
    End Function


    Sub alterar()
        Try
            If (Me.pveicodigo = 0 Or Me.pcomcodigo = 0) Then
                Throw New Exception("Preencha todos os campos")
            Else
                objDAL = New CombustiveisVeiculosDAL
                objDAL.alterar(Me.pveicodigo, Me.com_codigo)
            End If
        Catch ex As Exception
            Throw ex
        End Try
        objDAL = Nothing
    End Sub


End Class
